package test.core.safe;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;

import hyl.core.safe.MyBase64;
import hyl.core.safe.RsaCert;
import hyl.core.safe.MyRsa;

public class testcert {
	public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {

		test();
		// test2() ;

	}

	/**
	 * 
	 * @throws IOException
	 * @throws NoSuchAlgorithmException
	 * @throws InvalidKeySpecException
	 */
	public static void test() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
		RsaCert k1 = RsaCert.getInstance();
		k1.load公私钥PEM("./cert");

		String kp = k1.get公钥Base64();
		String kp2 = k1.get私钥Base64();
		System.out.println(kp);
		System.out.println(kp2);
		PublicKey pKey = MyRsa.generate64公钥(kp);
		PrivateKey pKey2 = MyRsa.generate64私钥(kp2);

		String data = "经常V了时间为哦累托if给收到经理看看估!@#@#%^%*&%*^()计是你的g";
		String 密文 = MyRsa.f公钥加密64(pKey, data);
		String 新文 = MyRsa.f私钥解密64(pKey2, 密文);

		System.out.println(新文);

		密文 = MyRsa.f私钥加密64(pKey2, data);
		新文 = MyRsa.f公钥解密64(pKey, 密文);

		System.out.println(新文);
	}

	public static void test2() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
		RsaCert k1 = RsaCert.getInstance();
		k1.load公私钥PEM("./cert");

		PublicKey pubkey = k1.get公钥();
		PrivateKey prikey = k1.get私钥();

		String data = "经常V了时间为哦累托if给收到经理看看估!@#@#%^%*&%*^()计是你的g";
		String 密文 = MyRsa.f公钥加密64(pubkey, data);
		String 新文 = MyRsa.f私钥解密64(prikey, 密文);

		System.out.println(新文);

		密文 = MyRsa.f私钥加密64(prikey, data);
		新文 = MyRsa.f公钥解密64(pubkey, 密文);

		System.out.println(新文);
	}
}
